#-*-coding:utf8-*-
from django.http import HttpResponse
from Model.models import Shop,TicketType,Ticket,Order
import json
def ticket_info(request):
    '''
    @author xjx
    @email arthursnoopyxu@foxmail.com
    @date 2017-9-24 14:21
    商家信息票类信息，所有商家信息，票类简介，票类名称，|| 单个票类 票类id 数量||订单数组所有信息 ||注意电子码    
    '''

    if request.method == 'GET':
        requestValue = request.GET['ticketId']

        ticketMsg = []
        ticket=Ticket.objects.get(id=requestValue)
        ticketId = ticket.id
        ticketNumber = ticket.ticket_num
        orderId = ticket.order_id
        ticketFailTime = str(ticket.fail_ticket_time)
        ticketBirthTime = str(ticket.ticket_birth_time)
        ticketTypeId = ticket.ticket_type_id
        realPayMoney = ticket.real_pay_money
        failBit = ticket.fail_bit
        ticketMsg.append({'ticketId':ticketId,'ticketNumber':ticketNumber,'orderId':orderId,
        'ticketFailTime':ticketFailTime,'ticketBirthTime':ticketBirthTime,
        'ticketTypeId':ticketTypeId,'realPayMoney':realPayMoney,
        'failBit':failBit,
        })

        order = Order.objects.get(id = orderId)
        orderInfo = []
        orderBirthTime = order.order_birth_time
        wechatId = order.wechat_id
        price = order.price
        count = order.count
        sumPrice = order.sum_price
        orderStatus = order.order_status
        orderInfo.append({'orderBirthTime':orderBirthTime,'wechatId':wechatId,
        'price':price,'count':count,'sumPrice':sumPrice,'orderStatus':orderStatus,
        })

        tickets=TicketType.objects.get(id=ticketTypeId)
        ticketType = []
        ticketKindName = tickets.ticket_name
        ticketKindOriginalPrice = tickets.original_price
        ticketKindPrice = tickets.price
        shopId = tickets.shop_id
        ticketTypeName = tickets.ticket_type
        ticketKindInfo = tickets.comment
        ticketKindEffectiveTime = str(tickets.effective_time)
        ticketKindAvatar = tickets.avatar
        ticketKindFailBit = tickets.fail_bit
        ticketType.append({'shopId':shopId,'ticketKindName':ticketKindName,'ticketKindOriginalPrice':ticketKindOriginalPrice,
        'ticketKindPrice':ticketKindPrice,'ticketTypeName':ticketTypeName,
        'ticketKindInfo':ticketKindInfo,'ticketKindEffectiveTime':ticketKindEffectiveTime,
        'ticketKindAvatar':ticketKindAvatar,'ticketKindFailBit':ticketKindFailBit,
        })


        shop=Shop.objects.get(id=shopId)
        shopInfo = []
        shopAvatar = shop.avatar
        shopPic = shop.shop_pic
        shopName = shop.shop_name
        shopArea = shop.area
        shopAddress = shop.detail_address
        price = shop.price
        shopPrice = shop.original_price
        html=shop.html
        shopInfo.append({'shopAvatar':shopAvatar,
	'shopName':shopName,'shopAddress':shopAddress,
        'price':price,'shopPic':shopPic,
        'shopPrice':shopPrice,'html':html,
        })


        kindInfo={'ticketMsg':ticketMsg,'orderInfo':orderInfo,'shopInfo':shopInfo,'ticketType':ticketType}
        return HttpResponse(json.dumps(kindInfo, ensure_ascii=False), content_type="application/json;charset=utf8")
    else:
        return HttpResponse(json.dumps({'error':404}, ensure_ascii=False), content_type="application/json;charset=utf8")
